﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AnimaGestionPersonnage.Utilities;

namespace AnimaGestionPersonnage.Vue
{
    public partial class FormEditionSelection : Form
    {
        private Object chosenItem = null;

        public FormEditionSelection()
        {
            InitializeComponent();
        }

        public CharacterClass ShowDialog(FormCreateCharClass parent)
        {
            SuspendLayout();

            this.Text = "Choisissez une Classe";

            listBoxClass.Items.Clear();
            listBoxClass.Items.AddRange(Utils.classList.ToArray());

            ResumeLayout();

            base.ShowDialog(parent);

            return (CharacterClass)chosenItem;
        }

        public Race ShowDialog(FormCreateRace parent)
        {
            SuspendLayout();

            this.Text = "Choisissez une Race";

            listBoxClass.Items.Clear();
            listBoxClass.Items.AddRange(Utils.racesList.ToArray());

            ResumeLayout();

            base.ShowDialog(parent);

            return (Race)chosenItem;
        }

        public AdvDisadv ShowDialog(FormCreateAdvDisadv parent)
        {
            SuspendLayout();

            this.Text = "Choisissez un Avantage/Désaventage";

            listBoxClass.Items.Clear();
            listBoxClass.Items.AddRange(Utils.advDisadvList.ToArray());

            ResumeLayout();

            base.ShowDialog(parent);

            return (AdvDisadv)chosenItem;
        }

        public Weapon ShowDialog(FormCreateWeapon parent)
        {
            SuspendLayout();

            this.Text = "Choisissez une Arme";

            listBoxClass.Items.Clear();
            listBoxClass.Items.AddRange(Utils.weaponList.ToArray());

            ResumeLayout();

            base.ShowDialog(parent);

            return (Weapon)chosenItem;
        }

        public TypicalModule ShowDialog(FormCreateTypicalModule parent)
        {
            SuspendLayout();

            this.Text = "Choisissez un Module Typique";

            listBoxClass.Items.Clear();
            listBoxClass.Items.AddRange(Utils.weaponModuleList.ToArray());

            ResumeLayout();

            base.ShowDialog(parent);

            return (TypicalModule)chosenItem;
        }

        public CombatModule ShowDialog(FormCreateCombatModule parent)
        {
            SuspendLayout();

            this.Text = "Choisissez un Module de Combat";

            listBoxClass.Items.Clear();
            listBoxClass.Items.AddRange(Utils.combatModuleList.ToArray());

            ResumeLayout();

            base.ShowDialog(parent);

            return (CombatModule)chosenItem;
        }

        private void buttonChoose_Click(object sender, EventArgs e)
        {
            if (listBoxClass.SelectedItem != null)
            {
                if (Utils.classList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.classList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.classList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
                if (Utils.racesList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.racesList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.racesList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
                if (Utils.advDisadvList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.advDisadvList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.advDisadvList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
                if (Utils.advDisadvList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.advDisadvList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.advDisadvList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
                if (Utils.weaponList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.weaponList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.weaponList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
                if (Utils.weaponModuleList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.weaponModuleList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.weaponModuleList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
                if (Utils.combatModuleList.Count > listBoxClass.SelectedIndex)
                {
                    if (Utils.combatModuleList[listBoxClass.SelectedIndex].name.Equals(listBoxClass.SelectedItem.ToString()))
                    {
                        chosenItem = Utils.combatModuleList[listBoxClass.SelectedIndex];
                        Dispose();
                    }
                }
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            chosenItem = null;
            Dispose();
        }

        private void FormClassEditionSelection_FormClosing(object sender, EventArgs e)
        {
        }
    }
}
